#coding=gbk
import initpath

import gevent
import gevent.server
import gevent.socket
from handler import ServerHandler
import authclient
import dbclient

BUF_SIZE = 1024

def handle_request(sock,addr):
	print 'handle %s connect'%str(addr)
	player_handler = ServerHandler(sock)
	#sock.close()
	print 'handle finish'

def start_server():
	authclient.init_service()
	dbclient.init_service()
	server = gevent.server.StreamServer(('',2345),handle_request)
	print 'start server...' 
	jobs = [server.serve_forever,]
	green_jobs = [gevent.spawn(job) for job in jobs]
	gevent.joinall(green_jobs)

if __name__ == '__main__':
	start_server()
